"""
Compliance Item 相关的请求和响应模型
"""
from datetime import datetime
from typing import Optional, List
from uuid import UUID
from pydantic import BaseModel, Field, field_validator
from schemas.attachment import  AttachmentResponse

class ComplianceItemBase(BaseModel):
    """
    Compliance Item 基本模型，包含共用属性
    """
    title: str = Field(..., description="标题")
    description: Optional[str] = Field(None, description="描述")
    guide: Optional[str] = Field(None, description="指导说明")
    inspector: Optional[str] = Field(None, description="检查人")
    compliance_type: str = Field(..., description="合规类型", pattern="^(risk|guarantee)$")
    compliance_status: str = Field(
        "non-compliant", 
        description="合规状态", 
        pattern="^(non-compliant|partially-compliant|fully-compliant|not-applicable)$"
    )
    maturity_level: Optional[int] = Field(None, description="成熟度等级")
    risk_level: Optional[str] = Field(
        None, 
        description="风险级别", 
        pattern="^(very-high|high|medium|low|very-low|not-applicable)$"
    )
    progress_status: str = Field(
        "in-progress", 
        description="进度状态", 
        pattern="^(in-progress|remediation|completed)$"
    )
    source_type: str  = Field(
        "system",
        description="模版来源标识", 
    )

class ComplianceItemCreate(ComplianceItemBase):
    """
    创建 Compliance Item 的请求模型
    """
    assessment_plan_id: UUID = Field(..., description="关联的业务系统ID")


class ComplianceItemUpdate(BaseModel):
    """
    更新 Compliance Item 的请求模型，所有字段都是可选的
    """
    title: Optional[str] = Field(None, description="标题")
    description: Optional[str] = Field(None, description="描述")
    guide: Optional[str] = Field(None, description="指导说明")
    inspector: Optional[str] = Field(None, description="检查人")
    compliance_type: Optional[str] = Field(None, description="合规类型", pattern="^(risk|guarantee)$")
    maturity_level: Optional[int] = Field(None, description="成熟度等级")
    risk_level: Optional[str] = Field(
        None, 
        description="风险级别", 
        pattern="^(very-high|high|medium|low|very-low|not-applicable)$"
    )
    compliance_status: Optional[str] = Field(
        None, 
        description="合规状态", 
        pattern="^(non-compliant|partially-compliant|fully-compliant|not-applicable)$"
    )
    progress_status: Optional[str] = Field(
        None, 
        description="进度状态", 
        pattern="^(in-progress|remediation|completed)$"
    )
    

class ComplianceItemResponse(ComplianceItemBase):
    """
    Compliance Item 响应模型，包含所有字段
    """
    id: UUID = Field(..., description="唯一标识符")
    assessment_plan_id: UUID = Field(..., description="关联的业务系统ID")
    attachments: List[AttachmentResponse] = Field(..., description="关联的附件信息")
    related_guarantees: List[str] = Field(..., description="关联的保障项")
    updated_at: datetime = Field(..., description="更新时间")

    class Config:
        """Pydantic配置类"""
        from_attributes = True

class ComplianceItemPagination(BaseModel):
    """
    分页查询响应模型
    """
    total: int = Field(..., description="总记录数")
    items: List[ComplianceItemResponse] = Field(..., description="当前页数据")
